package subject.tengxun.middle;

import java.util.HashSet;
import java.util.Set;

/**
 * 功能：
 * 作者：yedou
 * 日期：2025/3/16 12:16
 */
public class lengthOfLongestSubstring {

    public static void main(String[] args) {
        String s = "pwwkew";
        //  存储当前窗口的字符
        Set<Character> charSet = new HashSet<>();
        int left = 0;
        int maxLength = 0;

        for (int right = 0; right < s.length(); right++) {
            char currentChar = s.charAt(right);
            while (charSet.contains(currentChar)) {
                charSet.remove(s.charAt(left));
                left = left + 1;
            }
            charSet.add(currentChar);
            maxLength = Math.max(maxLength, right - left + 1);
        }
        System.out.println(maxLength);
    }
}